#include "LabInfoSetView.h"
#include "ui_LabInfoSetForm.h"


LabInfoSetView::LabInfoSetView(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::LabInfoSet)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint);
    m_settingHelper = SettingHelper::getSettingHelper();
    readSetting();
}

LabInfoSetView::~LabInfoSetView()
{
    delete ui;
}

void LabInfoSetView::readSetting()
{
    m_settingHelper->labInfoReadSetting();//将配置文件中的内容读到实验室结构体

    ui->ch_lineEditName->setText(m_settingHelper->m_LabInfoSet.hospital);
    ui->ch_lineEditLabName->setText(m_settingHelper->m_LabInfoSet.labName);
    ui->ch_lineEditOfficer->setText(m_settingHelper->m_LabInfoSet.officer);
    ui->ch_lineEditContact->setText(m_settingHelper->m_LabInfoSet.contact);
    ui->nu_lineEditMail->setText(m_settingHelper->m_LabInfoSet.mail);
    ui->ch_lineEditType->setText(m_settingHelper->m_LabInfoSet.type);
    ui->ch_lineEditSerialNumb->setText(m_settingHelper->m_LabInfoSet.numb);
    QString dateStr = m_settingHelper->m_LabInfoSet.date;
    ui->nu_dateEdit->setDateTime(QDateTime::fromString(dateStr,"yyyy-MM-dd"));
    ui->ch_lineEditAfterSale->setText(m_settingHelper->m_LabInfoSet.afterSale);
    ui->ch_lineEditSaleContact->setText(m_settingHelper->m_LabInfoSet.saleContact);
    ui->ch_textEditRemark->setText(m_settingHelper->m_LabInfoSet.remark);
}

void LabInfoSetView::writeSetting()
{
    m_settingHelper->m_LabInfoSet.hospital = ui->ch_lineEditName->text();
    m_settingHelper->m_LabInfoSet.labName = ui->ch_lineEditLabName->text();
    m_settingHelper->m_LabInfoSet.officer = ui->ch_lineEditOfficer->text();
    m_settingHelper->m_LabInfoSet.contact = ui->ch_lineEditContact->text();
    m_settingHelper->m_LabInfoSet.mail = ui->nu_lineEditMail->text();
    m_settingHelper->m_LabInfoSet.type = ui->ch_lineEditType->text();
    m_settingHelper->m_LabInfoSet.numb = ui->ch_lineEditSerialNumb->text();
    m_settingHelper->m_LabInfoSet.date = ui->nu_dateEdit->text();
    m_settingHelper->m_LabInfoSet.afterSale = ui->ch_lineEditAfterSale->text();
    m_settingHelper->m_LabInfoSet.saleContact = ui->ch_lineEditSaleContact->text();
    m_settingHelper->m_LabInfoSet.remark = ui->ch_textEditRemark->toPlainText();

    m_settingHelper->labInfoWriteSetting();
}

void LabInfoSetView::closeEvent(QCloseEvent *e)
{
    Q_UNUSED(e);
    writeSetting();
}
